package com.jztchat.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jztchat.dataobject.MessageInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import util.KeyUtils;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 聊天记录实体类
 * Created by zzy on 2018/1/18.
 */
@Entity
@Table(name = "tb_chat_record")
@Data
public class ChatRecord {

    @Id
    @NotNull
    private String recordId;

    private String sourceUser;

    private String targetUser;

    private Date  createTime;

    private String Content;

    @ApiModelProperty("是否发送 1：已发送 2：未发送")
    private Integer isSend;


    @JsonIgnore
    public static ChatRecord getChatRecord(MessageInfo sendData, String sourceId, String targetId, Integer isSend){
        ChatRecord chatRecord=new ChatRecord();
        chatRecord.setSourceUser(sourceId);
        chatRecord.setTargetUser(targetId);
        chatRecord.setContent(sendData.getMsgContent());
        chatRecord.setCreateTime(new Date());
        chatRecord.setRecordId(KeyUtils.getUniqueKey());
        chatRecord.setIsSend(isSend);
        return chatRecord;
    }

}
